//
//  DH.swift
//  DHLive
//
//  Created by Mac on 2021/7/1.
//

import Foundation
import UIKit
struct DH<Base> {
    var base: Base
    init(_ base: Base) {
        self.base = base
    }
}

protocol DHCompatible {}
extension DHCompatible {
    var dh: DH<Self> {
        set {}
        get {DH(self)}
    }
    static var dh: DH<Self>.Type {
        set {}
        get {DH<Self>.self}
    }
}

extension String: DHCompatible {}
extension NSString: DHCompatible {}

extension DH where Base: ExpressibleByStringLiteral {
    var toController: UIViewController? {
        guard let nameSpace = Bundle.main.infoDictionary?["CFBundleExecutable"] as? String else {
            print("没有命名空间")
            return nil
        }
        guard let className = NSClassFromString(nameSpace + "." + (base as! String)) else {
            print("没有对应的类名")
            return nil
        }
        
        guard let classVC = className as? UIViewController.Type else {
            print("没有转成对应的控制器类型")
            return nil
        }
        return classVC.init()
    }
}


